/*刚加载页面的时候焦点移到用户名文本框内*/
function myFocus() {
    document.getElementById("account").focus();
}

/*验证输入值*/
function checkAccount() {
    var email = document.getElementById("email").value;
    var password = document.getElementById("password").value;

    if (email == "null" || email ==""){
        alert("邮箱不能为空！")
    } else if(password == null || password == ""){
        alert("密码不能为空！")
    } else {
        $.ajax({
            url:"http://123.206.47.215:8081/club_student/studentLogin",
            //url:"./testData/login.json",
            type:"GET",
            data:
                {
                    "email":$("#userName").val(),
                    "password":$("#password").val()
                },
            dataType:"json",
            success: function (data) {
                alert(data.toString());
                if (data.success=="false") {
                    alert(data.message);
                }else {
                    alert("success");

                    //增加的保存cookie代码
                    var exp = new Date();
                    exp.setTime(exp.getTime() + 60 * 1000 * 60 * 6); //6小时
                    document.cookie = "user_identify=" + data.data.id + ";expires=" + exp.toGMTString();
                    document.cookie = "user_name=" + data.data.name + ";expires=" + exp.toGMTString();
                    //新增结束
                    window.location.href="index.html";
                }
            },
            error: function () {
                alert("请求失败！")
            }
        })
    }
}